<template>
	<view class="chongzhi_box">
		<view class="top_box">
			<u-icon name="account-fill" size="40" color="#329efd"></u-icon>
			<view style="font-weight: 500; font-size: 32rpx"
				>就诊号：0046644852 <text style="padding-left: 20rpx">李四</text></view
			>
		</view>
		<!-- 充值金额 -->
		<view class="jine">
			<view
				:class="{ money: idx == index }"
				v-for="(item, index) in moneyList"
				:key="index"
				@click="moneyClik(index, item)"
				>{{ item.number }}{{ index == 5 ? '' : '元' }}</view
			>
		</view>
		<view>
			<view class="input_money">
				<u-form
					ref="uForm"
					:rules="rules"
					:model="model"
					:errorType="errorType"
				>
					<u-form-item prop="money">
						<u-input
							type="number"
							v-if="idx == 5"
							v-model="model.money"
							placeholder="请输入金额"
							:clearable="false"
							:custom-style="{
								background: '#f5f5f5',
								padding: '0',
								borderRadius: '10rpx',
							}"
							@input="input_input"
							@focus="inputBlur"
						/>
					</u-form-item>
				</u-form>
			</view>
		</view>
		<!-- 方式 -->
		<view style="font-size: 40rpx; padding: 30rpx 40rpx">
			<view style="display: flex"
				><u-icon name="rmb-circle-fill" size="60" color="#1ebd0b"></u-icon
				><view style="margin-left: 20rpx; display: inline-block"
					>仅支持微信支付</view
				></view
			>
		</view>
		<view class="zhifu_button">
			<u-button
				@click="zhifu"
				:disabled="model.money == '' ? true : false"
				type="primary"
				>立即支付</u-button
			>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// value: '',
			model: {
				money: '',
			},

			disabled: false,
			moneyList: [
				{ number: '50' },
				{ number: '100' },
				{ number: '200' },
				{ number: '300' },
				{ number: '500' },
				{ number: '其他' },
			],
			idx: -1,

			rules: {
				money: [
					{
						required: true,
						message: '请输入金额',
						trigger: ['change', 'blur'],
					},
					{
						// 正则不能含有两边的引号
						pattern:
							/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
						message: '请输入正确的金额',
						trigger: ['change', 'blur'],
					},
				],
			},
			errorType: ['message'],
		}
	},
	methods: {
		input_input() {
			console.log(this.model.money)
		},
		inputBlur() {
			this.show = true
		},
		moneyClik(index, item) {
			this.model.money = item
			this.idx = index
			if (index == 5) {
				this.model.money = ''
			} else {
				this.model.money = item.number
			}
		},
		zhifu() {
			this.$refs.uForm.validate(valid => {
				if (valid) {
					console.log('验证通过')
				} else {
					console.log('验证失败')
				}
			})
			console.log(parseFloat(this.model.money).toFixed(2), '提交金额')
			console.log('成功')
		},
	},
}
</script>

<style lang="scss">
.chongzhi_box {
	.top_box {
		padding: 30rpx 20rpx;
		background-color: #fff;
		view {
			display: inline-block;
			margin-left: 20rpx;
		}
	}
	.jine {
		display: flex;
		flex-wrap: wrap;
		background: #fff;
		padding: 0 20px;
		justify-content: center;
		view {
			width: calc(100% / 3 - 20px - 10px);
			background: rgba(233, 233, 233, 0.815);
			color: #000;
			font-size: 32rpx;
			border-radius: 10rpx;
			margin: 20rpx;
			padding: 20rpx;
			text-align: center;
			border: 1px solid #fff;
		}
		.money {
			color: #004eff;
			background: #078bff45;
			border: 1px solid blue;
		}
	}
	.input_money {
		padding: 20rpx;
		background-color: #fff;
	}
	.zhifu_button {
		position: fixed;
		bottom: 0px;
		left: 0px;
		right: 0px;
		width: 90%;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 40rpx;
	}
}
</style>